package com.authorization.project.single.controller;

import java.util.List;

import com.authorization.project.single.domain.SingleAuthorization;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.authorization.framework.aspectj.lang.annotation.Log;
import com.authorization.framework.aspectj.lang.enums.BusinessType;
import com.authorization.project.single.domain.SingleService;
import com.authorization.project.single.service.ISingleServiceService;
import com.authorization.framework.web.controller.BaseController;
import com.authorization.framework.web.domain.AjaxResult;
import com.authorization.common.utils.poi.ExcelUtil;
import com.authorization.framework.web.page.TableDataInfo;

/**
 * 单服务Controller
 * 
 * @author 李晓雷
 * @date 2020-07-11
 */
@RestController
@RequestMapping("/single/service")
public class SingleServiceController extends BaseController
{
    @Autowired
    private ISingleServiceService singleServiceService;

    /**
     * 查询单服务列表
     */
    @PreAuthorize("@ss.hasPermi('single:service:list')")
    @GetMapping("/list")
    public TableDataInfo list(SingleService singleService)
    {
        startPage();
        List<SingleService> list = singleServiceService.selectSingleServiceList(singleService);
        return getDataTable(list);
    }

    @GetMapping("/listAll")
    public AjaxResult listAll(SingleService singleService)
    {
        List<SingleService> list = singleServiceService.selectSingleServiceList(singleService);
        return AjaxResult.success(list);
    }

    /**
     * 导出单服务列表
     */
    @PreAuthorize("@ss.hasPermi('single:service:export')")
    @Log(title = "单服务", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SingleService singleService)
    {
        List<SingleService> list = singleServiceService.selectSingleServiceList(singleService);
        ExcelUtil<SingleService> util = new ExcelUtil<SingleService>(SingleService.class);
        return util.exportExcel(list, "service");
    }

    /**
     * 获取单服务详细信息
     */
    @PreAuthorize("@ss.hasPermi('single:service:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(singleServiceService.selectSingleServiceById(id));
    }

    /**
     * 新增单服务
     */
    @PreAuthorize("@ss.hasPermi('single:service:add')")
    @Log(title = "单服务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SingleService singleService)
    {
        return toAjax(singleServiceService.insertSingleService(singleService));
    }

    /**
     * 修改单服务
     */
    @PreAuthorize("@ss.hasPermi('single:service:edit')")
    @Log(title = "单服务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SingleService singleService)
    {
        return toAjax(singleServiceService.updateSingleService(singleService));
    }

    /**
     * 删除单服务
     */
    @PreAuthorize("@ss.hasPermi('single:service:remove')")
    @Log(title = "单服务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(singleServiceService.deleteSingleServiceByIds(ids));
    }
}
